package com.wtgroup.demo.mianshi.线程.d02_condition_await_signal;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/3/7 16:16
 */
public class D {
    public static void main(String[] args) {
        D d = new D();
        /*
        和 wait/notify 一样, 调用前必须实现获取锁, 否则, java.lang.IllegalMonitorStateException
        `Thread.currentThread() != getExclusiveOwnerThread()`
        */
        // d.conditionWait();
        // d.conditionSignal();
    }


    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();

    public void conditionWait() {
        try {
            condition.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void conditionSignal() {
        condition.signal();
    }
}
